<?php
namespace app\service;

use think\facade\Db;

class LogService
{
    public static function record(
        int $userId,
        string $operateType,
        string $module,
        string $ipAddress,
        array $operateDetail,
        bool $status,
        string $errorMessage,
        string $requestMethod,
        string $requestPath
    ) {
        Db::name('operation_log')->insert([
            'user_id' => $userId,
            'operate_type' => $operateType,
            'module' => $module,
            'operate_time' => date('Y-m-d H:i:s'),
            'ip_address' => $ipAddress,
            'operate_detail' => json_encode($operateDetail, JSON_UNESCAPED_UNICODE),
            'status' => $status ? 1 : 0,
            'error_message' => $errorMessage,
            'request_method' => $requestMethod,
            'request_path' => $requestPath
        ]);
    }
}
